package beans;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String[] args) {
		HelloTest helloTest = new HelloTest();
		helloTest.setName("xiaoming");
		helloTest.hello();

		
//		//创建spring的IOC容器对象
//		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//		//从容器中获取Bean实例
//		HelloTest beanTest = (HelloTest)ctx.getBean("helloTest");
//		//调用函数
//		beanTest.hello();
//		
//		//构造器方式注入
//		Car newcar = (Car)ctx.getBean("car");
//		newcar.show();
//		
//		//bean之间的引用
//		Person person = (Person)ctx.getBean("person");
//		System.out.println(person.toString());
//
//		//bean内部构造的bean
//		Person person1 = (Person)ctx.getBean("person1");
//		System.out.println(person1.toString());
//		
//		//级联属性
//		Person person2 = (Person)ctx.getBean("person2");
//		System.out.println(person2.toString());
//		
//		//结合属性
//		Person person3 = (Person)ctx.getBean("person3");
//		person3.showCars();
//		person3.showMap();
//		
//		//结合属性
//		Person person4 = (Person)ctx.getBean("person4");
//		person4.showCars();
//		System.out.println(person4.toString());
		
		
		
		
		ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext("application1.xml");
		City city = (City)ctx1.getBean("city");
		City city1 = (City)ctx1.getBean("city1");
		System.out.println(city.toString());
		System.out.println(city1.toString());
		
		//验证这个bean是否是从单利中获取到的 默认是singleton
		Car car1 = (Car)ctx1.getBean("car");
		Car car2 = (Car)ctx1.getBean("car");
		if (car1 == car2) {
			System.out.println("是同一个car");
		}
		else {
			System.out.println("不是同一个");
		}
		
		//spel
		City city2 = (City)ctx1.getBean("city2");
		System.out.println(city2.toString());
		
		
		//静态工厂方法生成car
		Car car3 = (Car)ctx1.getBean("car1");
		System.out.println(car3.toString());
		//实例工厂方法生成的car
		Car car4 = (Car)ctx1.getBean("car2");
		System.out.println(car4.toString());
		//继承FactoryBean协议生成的car
		Car car5 = (Car)ctx1.getBean("car3");
		System.out.println(car5.toString());
		
		
		ctx1.close();
	}
}
